package com.triones.api.controller.web.interlace;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.triones.api.entity.HelpDO;
import com.triones.api.entity.interlace.dto.InterlaceCurrencyChainDO;
import com.triones.api.entity.interlace.dto.InterlaceCurrencyDO;
import com.triones.api.entity.interlace.vo.InterlaceCurrencyChainVO;
import com.triones.api.entity.interlace.vo.InterlaceCurrencyVO;
import com.triones.api.entity.vo.HelpCategorizeVO;
import com.triones.api.entity.vo.HelpVO;
import com.triones.api.service.interlace.InterlaceCurrencyChainService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 币种链管理
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/interlace/currencyChain")
public class InterlaceCurrencyChainController extends BaseController {

    private final InterlaceCurrencyChainService interlaceCurrencyChainService;

    /**
     * 查询币种列表（分页）
     */
    @SaCheckPermission("system:currency:pageList")
    @GetMapping("/currency/pageList")
    public TableDataInfo<InterlaceCurrencyVO> pageList(InterlaceCurrencyDO dto, PageQuery pageQuery) {
        return interlaceCurrencyChainService.pageList(dto, pageQuery);
    }

    /**
     * 查询币种详情
     */
    @SaCheckPermission("system:currency:query")
    @GetMapping(value = "/currency/{id}")
    public R<InterlaceCurrencyVO> getCurrencyDetail(@PathVariable Long id) {
        return R.ok(interlaceCurrencyChainService.getCurrencyDetail(id));
    }

    /**
     * 新增币种
     */
    @SaCheckPermission("system:currency:add")
    @PostMapping("/currency")
    public R<Void> addCurrency(@Validated @RequestBody InterlaceCurrencyDO dto) {
        if (!interlaceCurrencyChainService.checkCurrency(dto)) {
            return R.fail("新增币种'" + dto.getCurrency() + "'失败，币种已存在");
        }
        return toAjax(interlaceCurrencyChainService.addCurrency(dto));
    }

    /**
     * 修改币种
     */
    @SaCheckPermission("system:currency:edit")
    @PutMapping("/currency")
    public R<Void> editCurrency(@Validated @RequestBody InterlaceCurrencyDO dto) {
        if (!interlaceCurrencyChainService.checkCurrency(dto)) {
            return R.fail("修改币种'" + dto.getCurrency() + "'失败，币种已存在");
        }
        return toAjax(interlaceCurrencyChainService.editCurrency(dto));
    }

    /**
     * 删除币种
     */
    @SaCheckPermission("system:currency:remove")
    @DeleteMapping("/currency/{id}")
    public R<Void> removeCurrency(@PathVariable Long id) {
        return toAjax(interlaceCurrencyChainService.removeCurrency(id));
    }

    /**
     * 获取币种选择列表
     */
    @GetMapping("/currency/optionList")
    public R<List<InterlaceCurrencyVO>> currencyOptionList() {
        return R.ok(interlaceCurrencyChainService.currencyOptionList());
    }

    /**
     * 查询链列表（分页）
     */
    @SaCheckPermission("system:chain:pageList")
    @GetMapping("/chain/pageList")
    public TableDataInfo<InterlaceCurrencyChainVO> chainPageList(InterlaceCurrencyChainDO dto, PageQuery pageQuery) {
        return interlaceCurrencyChainService.chainPageList(dto, pageQuery);
    }

    /**
     * 查询链详情
     */
    @SaCheckPermission("system:chain:query")
    @GetMapping(value = "/chain/{id}")
    public R<InterlaceCurrencyChainVO> getChainDetail(@PathVariable Long id) {
        return R.ok(interlaceCurrencyChainService.getChainDetail(id));
    }

    /**
     * 新增链
     */
    @SaCheckPermission("system:chain:add")
    @PostMapping("/chain")
    public R<Void> addChain(@Validated @RequestBody InterlaceCurrencyChainDO dto) {
        if (!interlaceCurrencyChainService.checkChain(dto)) {
            return R.fail("新增链'" + dto.getChain() + "'失败，链已存在");
        }
        return toAjax(interlaceCurrencyChainService.addChain(dto));
    }

    /**
     * 修改链
     */
    @SaCheckPermission("system:chain:edit")
    @PutMapping("/chain")
    public R<Void> editChain(@Validated @RequestBody InterlaceCurrencyChainDO dto) {
        if (!interlaceCurrencyChainService.checkChain(dto)) {
            return R.fail("修改链'" + dto.getChain() + "'失败，链已存在");
        }
        return toAjax(interlaceCurrencyChainService.editChain(dto));
    }

    /**
     * 删除链
     */
    @SaCheckPermission("system:chain:remove")
    @DeleteMapping("/chain/{id}")
    public R<Void> removeChain(@PathVariable Long id) {
        return toAjax(interlaceCurrencyChainService.removeChain(id));
    }

    /**
     * 获取币种选择列表
     */
    @GetMapping("/chain/optionList")
    public R<List<InterlaceCurrencyChainVO>> chainOptionList() {
        return R.ok(interlaceCurrencyChainService.chainOptionList());
    }
}
